'use strict';

module.exports = app => {
  const { model } = app;
  const { UUID, STRING } = app.Sequelize;

  const Category = model.define(
    'Category',
    {
      id: {
        type: UUID,
        primaryKey: true,
      },
      tag: {
        type: STRING(50),
        allowNull: false,
      },
      name: {
        type: STRING(50),
        allowNull: true,
      },
    },
    {
      tableName: 'cms_category',
    }
  );

  Category.associate = function() {
    const { Cms: { Article, Category } } = model;
    Category.hasMany(Article, { as: 'article', foreignKey: 'category_id' });
  };

  return Category;
};
